import mongoose  from 'mongoose'
import BaseModel from "./base_model"

let Schema    = mongoose.Schema;
let ObjectId  = Schema.ObjectId;
import config  from '../config'
import _       from 'lodash'

var TopicSchema = new Schema({
  appId:            { type: String, requried: true },
  zoneId:           { type: ObjectId, required: true },
  title:            { type: String, required: true },
  advertisingMap:   { type: String },
  content:          { type: String, required: true },
  author_id:        { type: ObjectId },
  top:              { type: Boolean, default: false },  // 置顶帖
  good:             { type: Boolean, default: false },   // 精华帖
  lock:             { type: Boolean, default: false },   // 被锁定主题
  reply_count:      { type: Number, default: 0 },
  visit_count:      { type: Number, default: 0 },
  collect_count:    { type: Number, default: 0 },
  create_at:        { type: Date, default: Date.now },
  update_at:        { type: Date, default: Date.now },
  last_reply:       { type: ObjectId },
  last_reply_at:    { type: Date, default: Date.now },
  content_is_html:  { type: Boolean },
  menu:             { type: String },
  submenu:          { type: String },
  deleted:          { type: Boolean, default: false },
  status:           { type: String },
  mdType:           { type: String, default: config.mdType },
  canReply:         { type: Boolean, default: true },
  tags:             { type: String },
  isHtml:           { type: Boolean, default: false },
  area:             { type: String },
  audioList:        [{type: String}]
});

TopicSchema.plugin(BaseModel);
TopicSchema.index({create_at: -1});
TopicSchema.index({top: -1, last_reply_at: -1});
TopicSchema.index({author_id: 1, create_at: -1});

mongoose.model('Topic', TopicSchema);
